﻿
using System.Collections.Generic;
using System.Data;
using System;
using ZHDJ.MobileInterface.Common;
namespace ZHDJ.MobileInterface
{
    public partial class RelationTransfer : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            RelationTransferOutParam result = new RelationTransferOutParam();
            RelationTransferInParam param = new RelationTransferInParam();
            string logMsg = "";
            bool isFlag = true;
            string branchID = "";
                 
            try
            {
                int ageInt = 0;
                param = inParam as RelationTransferInParam;

                if (string.IsNullOrEmpty(param.Explain) || string.IsNullOrEmpty(param.FromBranchAddress) 
                    || string.IsNullOrEmpty(param.FromBranchFax) || string.IsNullOrEmpty(param.FromBranchMobileNo)
                    || string.IsNullOrEmpty(param.FromBranchZip) || string.IsNullOrEmpty(param.LoginID) 
                    || string.IsNullOrEmpty(param.TageBranchID))
                {
                    result.code = "0";
                    result.desc = "登录ID、申请内容、目标组织、所属组织通讯地址、所属组织传真、所属组织联系电话、所属组织邮编不能为空";

                    isFlag = false;
                }

                if (isFlag)
                {
                    try
                    {
                        ageInt = Convert.ToInt32(param.Age);
                    }
                    catch
                    {
                        result.code = "0";
                        result.desc = "年龄不正确";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    branchID = InterfaceHelper.GetBranchID(param.TageBranchID);

                    if(string.IsNullOrEmpty(branchID))
                    { 
                        result.code = "0";
                        result.desc = "目标组织不存在";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {

                    string rfResult = ORelationTransfer.ORTransfer(param.LoginID, param.Explain, branchID, ageInt, param.FromBranchAddress, param.FromBranchFax,
                        param.FromBranchMobileNo, param.FromBranchZip, param.SerialNumber);

                    if (!string.IsNullOrEmpty(rfResult))
                    {
                        result.code = "0";
                        result.desc = rfResult;

                        isFlag = false;
                    }
                } 
                 
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "转移过程出现异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }
    
            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-RelationTransfer", SerializeHelper.JsonSerializer<RelationTransferInParam>(param), logMsg); 
            return result as OutParam;
        } 

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<RelationTransferInParam, RelationTransferOutParam>();
            else
                SafeProcessRequest<RelationTransferInParam, RelationTransferOutParam>();
        }
    }

    #region 请求参数
    public class RelationTransferInParam
    {
        /// <summary>
        ///	登录ID  必须
        /// </summary>
        public string LoginID
        { get; set; } 
    
        /// <summary>
        ///	申请内容 必须
        /// </summary>
        public string Explain
        { get; set; } 
    
        /// <summary>
        ///	目标组织 必须
        /// </summary>
        public string TageBranchID
        { get; set; }

        /// <summary>
        ///	年龄 必须
        /// </summary>
        public string Age
        { get; set; } 
    
        /// <summary>
        ///	所属组织通讯地址 必须
        /// </summary>
        public string FromBranchAddress
        { get; set; } 
    
        /// <summary>
        ///	所属组织传真 必须
        /// </summary>
        public string FromBranchFax
        { get; set; } 
    
        /// <summary>
        ///	所属组织联系电话 必须
        /// </summary>
        public string FromBranchMobileNo
        { get; set; } 
    
        /// <summary>
        ///	所属组织邮编 必须
        /// </summary>
        public string FromBranchZip
        { get; set; } 
    
        /// <summary>
        ///	编号 
        /// </summary>
        public string SerialNumber
        { get; set; } 
    }
    #endregion

    #region 结果参数
    public class RelationTransferOutParam
    {
        public RelationTransferOutParam()
        {
            code = "1";
            desc = "操作成功"; 
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; } 
    } 
    #endregion 
}